import jsonp from 'common/js/jsonp.js'
import axios from 'axios'

// 获取 主页数据
export function getSearchResult (keyword) {
  // encodeURI()
  const url = 'https://search.m.smzdm.com/api/keyword/suggestion_jsonp'
  /* eslint-disable */
  let randCallbackName = '__jp' + String(Math.random()).slice(2,8)
  let params = Object.assign({}, {
    '_': new Date().getTime(),
    keyword: keyword,
    callback: randCallbackName
  })
  return jsonp(url, params, { name: randCallbackName })
}

/* eslint-disable */
// 获取 查询结果详情页
export function getSearchResultDetail (suggest) {
  // https://search.m.smzdm.com/?s=%E7%94%B5%E8%A7%86%E6%9C%BA+65&v=b
  const url = '/apizdm/search-result-detail?s=' + suggest + '&v=b'
  return axios.get(url, {
  },  {timeout: 1000 * 20}).then((res) => {
    return Promise.resolve(res.data)
  })
}

export function testSourceTree() {
  const.log('sourceTree')
}
